const cloud = require('wx-server-sdk');
cloud.init();

exports.main = async (event, context) => {
  const db = cloud.database();
  const { openid } = event;

  const selectedStock = await db.collection('selectedStock').where({ openid }).get();

  if (selectedStock.data.length === 0) {
    return { selectedStocks: [] };
  } else {
    return { selectedStocks: selectedStock.data[0].stockCodes };
  }
};
